package com.tank.ui;

import com.almasb.fxgl.animation.Interpolators;
import com.almasb.fxgl.dsl.FXGL;
import com.almasb.fxgl.scene.SubScene;
import com.almasb.fxgl.texture.Texture;
import com.tank.constant.Config;
import javafx.animation.TranslateTransition;
import javafx.util.Duration;

public class FailedScene extends SubScene {

    private final TranslateTransition animationTransition;
    private final Texture texture;

    public FailedScene() {
        texture = FXGL.texture("ui/game_over.png");
        texture.setLayoutX(Config.GROUND_CELL_COUNT * Config.CELL_SIZE / 2.0 - texture.getWidth() / 2.0);
        texture.setLayoutY(FXGL.getAppHeight());
        animationTransition = new TranslateTransition(Duration.seconds(2.6), texture);
        animationTransition.setInterpolator(Interpolators.ELASTIC.EASE_OUT());
        animationTransition.setFromY(0);
        animationTransition.setToY(-(FXGL.getAppHeight() - 260));
        animationTransition.setOnFinished(event -> {
            FXGL.getSceneService().popSubScene();
            texture.setTranslateY(0);
            FXGL.getGameController().gotoMainMenu();
        });
        getContentRoot().getChildren().add(texture);
    }

    @Override
    public void onCreate() {
        animationTransition.play();
    }
}
